Skip to content

Handle null instance and fall back to SFC filename in Vue error handler - #679

Open
DWonnink wants to merge 2 commits into
appsignal:mainfrom
DWonnink:fix/vue-error-handler-null-instance-and-file-fallback
Open

DWonnink wants to merge 2 commits into
appsignal:mainfrom
DWonnink:fix/vue-error-handler-null-instance-and-file-fallback

Conversation

@DWonnink

Copy link
Copy Markdown

Fixes #678.

Two fixes to the @appsignal/vue error handler when used with Vue 3:

Null instance crash. Vue 3 invokes app.config.errorHandler(err, instance, info) with instance: null for errors raised outside a component context (e.g. in watchers, or lifecycle hooks after unmount). The handler dereferenced the instance unguarded and threw a TypeError of its own, so the original error never reached AppSignal or console.error. It now reports these as [unknown Vue component].

Component name resolution on Vue 3. The $vnode branch is Vue 2 API (always undefined on Vue 3), $options.name requires an explicit name option, and __name only exists for <script setup> components. For classic Options API SFCs none of these match, so every error grouped under [unknown Vue component]. The handler now falls back to the basename of $options.__file, which vue-loader sets in development and, when the app enables its exposeFilename option, as a basename in production builds. When __file is absent the existing [unknown Vue component] fallback is preserved, so behaviour only changes for apps that opt in.

Includes a mono changeset (bump: patch, type: fix) and test coverage for the new branches: __file with a full path (development), basename-only __file (production), explicit name taking precedence, a null instance, and empty options. Verified locally with jest in packages/vue (8 passing) and prettier --check.

DWonnink and others added 2 commits September 14, 2026 13:13
Vue 3 invokes app.config.errorHandler with a null instance for errors
raised outside a component context; the handler crashed on it and lost
the original error. Component name resolution also never worked for
Options API SFCs without an explicit name: the $vnode branch is Vue 2
API and __name only exists for <script setup> components. Fall back to
the basename of $options.__file, set by vue-loader (in production
builds only when its exposeFilename option is enabled).

Fixes appsignal#678

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@appsignal/vue: errorHandler crashes on null instance and cannot resolve component names on Vue 3

1 participant